#include "Image.h"
#include "SDL/SDL_image.h"
#include <iostream>

Image::Image() //default constructor
{
}
Image::Image(std::string path)
{
	this->width = NULL;
	this->height = NULL;
	init(path);
}
Image::Image(std::string path, short width, short height)
{
	this->width = width;
	this->height = height;
	init(path);
}

void Image::init(std::string path)
{
	this->image = NULL;
	this->path = path;
   this->x = 0;
   this->y = 0;
}

Image::~Image(void)
{
	SDL_FreeSurface(image);
}

bool Image::load()
{
	image = IMG_Load(this->path.c_str());
	if (image == NULL)
    {
        std::cout << "loading " << path << " failed";
		return false;
    }
	image = SDL_DisplayFormat(image);

	return true;
}
void Image::update(short x, short y)
{
    this->x = x;
    this->y = y;
}
void Image::draw(SDL_Surface* screen)
{
	SDL_Rect offset;
	offset.x = this->x;
	offset.y = this->y;
	offset.w = this->width;
	offset.h = this->height;

	SDL_BlitSurface(image, NULL, screen, &offset);
}
